package bupt.xixi;

import bupt.xixi.netty.NettyClient;
import bupt.xixi.proxy.NettyClientProxyFactory;
import bupt.xixi.rpc.api.HelloObject;
import bupt.xixi.rpc.api.HelloService;
import bupt.xixi.rpc.api.Person;
import bupt.xixi.spring.RpcReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HelloController {

    @RpcReference
    private HelloService helloService;

    @Autowired
    private NettyClient nettyClient;

    public void test() {
        // 注解方式调用
        String hello = this.helloService.hello(new HelloObject(2019140606, "哈哈哈哈哈"));
        System.out.println(hello);
        // 动态代理方式调用
        NettyClientProxyFactory clientProxyFactory = new NettyClientProxyFactory(nettyClient);
        Person personProxy = clientProxyFactory.getProxy(Person.class);
        String result = personProxy.doSomething();
        System.out.println(result);

    }
}
